import {
	PickupViewPanelActionType,
	ICtrlEvent,
	IPickupViewPanelAbility,
	IPickupViewPanelControllerParams,
	IPickupViewPanelModel,
	IPickupViewPanelStore,
	IParam,
} from '@/core';
import { QXEvent } from 'qx-util';
import {
	getCtrlClassNames,
	handleCtrlAction,
	handleCtrlInit,
	useCtrlAction,
	useCtrlBasic,
	useCtrlControllerParams,
	useCtrlProps,
} from '../use-ctrl';

/**
 * 选择面板输入参数
 *
 * @export
 * @return {*}
 */
export function usePickupViewPanelProps() {
	return {
		...useCtrlProps(),
		openView: Function,
		newView: Function,
		singleSelect: Boolean,
	};
}

/**
 * 选择面板基础参数
 *
 * @export
 * @param {IPickupViewPanelModel} model
 * @param {IParam} props
 * @return {*}
 */
export function usePickupViewPanelBasic(
	model: IPickupViewPanelModel,
	props: IParam
) {
	const getClassNames = (props: IParam) => {
		const names = getCtrlClassNames(model, props);
		return names;
	};
	return {
		...useCtrlBasic(model, props),
		getClassNames,
		handleCtrlAction,
		handleCtrlInit,
	};
}

/**
 * 选择面板部件行为
 *
 * @export
 */
export function usePickupViewPanelAction(controller: any) {
	return {
		...useCtrlAction(controller),
	};
}

/**
 * 选择面板部件控制器
 *
 * @export
 */
export function usePickupViewPanelControllerParams<
	S extends IPickupViewPanelStore,
	M extends IPickupViewPanelModel
>(
	model: M,
	props: any,
	evt: QXEvent<ICtrlEvent<PickupViewPanelActionType, IPickupViewPanelAbility>>,
	otherParams: IParam = {}
): IPickupViewPanelControllerParams<
	PickupViewPanelActionType,
	IPickupViewPanelAbility
> {
	return {
		...useCtrlControllerParams<S, M>(model, props, evt, otherParams),
		openView: props.openView,
		newView: props.newView,
	};
}
